import { defineStore } from 'pinia'

export const domoStore = defineStore({
  id: 'myStore',
  // 这个函数会返回初始状态
  state: () => ({
    isZH_CN: true,
    menuList: [],//菜单
    targetType: '',//判断是不是iframe
    headMenuCurrentID: '',//选择当前菜单的id
    headMenuParentCurrentID: ''//选择当前菜单的最顶部父级id
  }),
  // 计算属性，基于 state 计算得到的结果
  getters: {
    test: (state) => `${state.isZH_CN} Doe`,
  },
  // 修改状态的方法
  actions: {
    updateHeadMenuCurrentID(headMenuCurrentID) {
      this.headMenuCurrentID = headMenuCurrentID
    },
    upHeadMenuParentCurrentID(data) {
      this.headMenuParentCurrentID = data
    },
    updateLanguage(isZH_CN) {
      this.isZH_CN = isZH_CN
    },
    updateMenu(menuList) {
      this.menuList = menuList
    },
    getTargetType(targetType) {
      this.targetType = targetType
    }
  },
  // 配置需要持久化的属性
  persist: {
    enabled: true, // 启用持久化
    key: 'myStore', // 本地存储的键
    storage: localStorage, // 使用 localStorage 存储
    paths: ['headMenuCurrentID', 'headMenuParentCurrentID']
  }
})